package com.xingkeduo.pojo.table;

import com.baomidou.mybatisplus.annotation.TableName;
import com.xingkeduo.pojo.enums.OrderStatus;
import com.xingkeduo.util.pojo.exception.BusinessException;
import com.xingkeduo.utils.DateTimeUtils;
import com.xingkeduo.utils.TableAnnotations;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import static com.xingkeduo.utils.DateTimeUtils.yyyy_MM_dd_HH_mm_ss;

/**
 * @author chi  2019-02-13 15:49
 **/
@EqualsAndHashCode(callSuper = true)
@Data
@Accessors(chain = true)
@TableName(value = "t_order_detail")
public class OrderDetail extends BaseTable<OrderDetail> {

    /**
     * 原先字段
     */
    @TableAnnotations("票类型 1全天票，2限时票")
    private int selectedTicketType;

    @TableAnnotations("客服管理的第三方（点评，百度糯米）的记录id")
    private int serviceId;

    @TableAnnotations("是否添加积分日志 0未添加 1已添加")
    private int isPoints;

    @TableAnnotations("是否发送过评论消息 0否1是")
    private int isSendMessage;

    @TableAnnotations("商品数量（商品下单或者随星付的都要有数量）")
    private int productNum;

    @TableAnnotations("")
    private String productIds;

    @TableAnnotations("商品信息详情（已经序列化）")
    private String productDetails;

    @TableAnnotations("0 未发送 1已发送")
    private int isSendPayMessage;

    @TableAnnotations("减免金额（五一活动用）")
    private BigDecimal reducePrice;

    @TableAnnotations("活动,0 无  1 新发型师优惠")
    private boolean activity;

    @TableAnnotations("期望等待时间")
    private int expectTime;

    @TableAnnotations("过期时间")
    private int expirationTime;

    @TableAnnotations("")
    private int excel;

    @TableAnnotations("队列类型1现场队列2预约队列（新逻辑中全部是2，此字段不参与统计）")
    private int mode;

    //可能会删除
    @TableAnnotations("对应t_wechat_account表中的id")
    private int wechatId;
    @TableAnnotations("商品id")
    private int productId;
    @TableAnnotations("是否有差价 0否 1是")
    private int isDifferencePrice;
    @TableAnnotations("差价金额")
    private BigDecimal differencePrice;
    @TableAnnotations("差价详情")
    private String differencePriceDetail;
    @TableAnnotations("差价商户订单号")
    private String differencePriceOutOrderNo;

    @TableAnnotations("订单号")
    private String orderNo;

    //活动详情
    private String activityDetail;

    //卡券详情
    private String cardCouponDetail;

    @TableAnnotations("叫号时间,以逗号分隔")
    private String announceNumberTimes;


    /**
     * 叫号
     */
    public void announceNumber() {
        this.announceNumberTimes = Optional.ofNullable(this.announceNumberTimes).orElse("") + LocalDateTime.now().format(yyyy_MM_dd_HH_mm_ss) + ",";
    }

    public List<LocalDateTime> announceCountlist() {

        if (this.announceNumberTimes == null) {
            return new ArrayList<>();
        }

        String[] split = this.announceNumberTimes.split(",");
        List<String> strings = Arrays.asList(split);
        strings.remove("");
        return strings.stream().map(DateTimeUtils::yyyy_MM_dd_H_m_s).collect(Collectors.toList());
    }
}
